package purchase

import (
	"LogisticsPort/model"
	"LogisticsPort/sql"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

/**
 *船务信息
 */
func shipping(r *gin.RouterGroup) {
	shipping := r.Group("/port")
	{
		shipping.POST(sql.RequestAdd, shippingAdd)
		shipping.POST(sql.RequestUpdate, shippingUpdate)
		shipping.GET(sql.RequestList, shippingList)
		shipping.GET(sql.RequestDelete, shippingDelete)
		shipping.GET(sql.RequestData, shippingData)
	}
}

func shippingAdd(c *gin.Context) {
	sql.HttpAddTable(c, "shipping_info", &model.ShippingInfoEdit{}, nil)
	//sql.HttpAdd(c, &model.PurchasePort{}, nil)

}

func shippingUpdate(c *gin.Context) {
	//sql.HttpUpdates(c, &model.PurchasePort{}, nil)
	sql.HttpUpdatesTable(c, "shipping_info", &model.ShippingInfoEdit{}, nil)
}

func shippingList(c *gin.Context) {
	sql.HttpList(c, &[]model.ShippingInfo{}, nil)
}

func shippingData(c *gin.Context) {
	sql.HttpData(c, &model.ShippingInfo{}, func(db *gorm.DB) *gorm.DB {
		if id := c.Query("purchaseProductId"); id != "" {
			db = db.Where("purchase_product_id", id)
		}
		db = db.Table("shipping_info")
		return db
	})
}

func shippingDelete(c *gin.Context) {
	sql.HttpDeleteById(c, &model.ShippingInfo{})
}
